<!--  -->
<template>
  <div class="all_container">
    <div v-if="loginStatus=='true'" class="content_warp">
      <div class="popover">
        <el-popover placement="bottom-start" title="全部视频" width="600" style="height: 400px" trigger="click" v-model="visible">
          <div class="tags">
            <div @click="getVideo(item.id,item.name)" v-for="(item, index) in tags" :key="index">
              {{ item.name }}
            </div>
          </div>
          <el-button slot="reference">{{title}}</el-button>
        </el-popover>
      </div>
      <div class="mv-wrapper">
        <div class="video_wrap">
          <div
            class="item_wrap"
            v-for="(item, index) in videoList"
            :key="index"
          >
            <div class="item">
              <div class="cover">
                <el-image
                  @click="toDetail(item.data.vid)"
                  :src="
                    item.data.coverUrl
                      ? item.data.coverUrl
                      : 'https://cube.elemecdn.com/6/94/4d3ea53c084bad6931a56d5158a48jpeg.jpeg'
                  "
                  fit="cover"
                ></el-image>
              </div>
              <div class="title">
                {{ item.data.title ? item.data.title : "暂无视频信息" }}
              </div>
              <div v-if="item.data.creator" class="name">{{ item.data.creator.nickname}}</div>

            </div>
          </div>
        </div>
      </div>
    </div>

    <div v-else class="block">
      <el-empty description="请登录后使用此功能哦"></el-empty>
    </div>

  </div>
</template>

<script>
import { getVideo, getAllVideo } from 'util/video.js'
import { mapGetters } from 'vuex'

export default {
  name: '',
  props: {
    tags: []
  },
  data() {
    return {
      videoList: [],
      visible: false,
      title: '全部视频'
    }
  },
  computed: {
    ...mapGetters('userInfo', ['loginStatus'])
  },

  created() {
    if (this.loginStatus == 'true') {
      this.getAllVideo()
    }
  },
  watch: {
    loginStatus(newVal) {
      if (newVal == true) {
        this.getAllVideo()
      }
    }
  },
  methods: {
    async getVideo(id, name) {
      let {
        data: { datas }
      } = await getVideo(id)
      this.videoList = datas
      this.visible = false
      this.title = name
      // console.log(datas);
    },
    async getAllVideo() {
      let {
        data: { datas }
      } = await getAllVideo()
      // console.log(datas);
      this.videoList = datas
    },
    toDetail(id) {
      this.$store.dispatch('musicPlay/saveIsPlaying', false)

      this.$router.push('/videoDetail/' + id)
    }
  }
}
</script>

<style scoped  lang='less'>
.popover .el-button {
  width: 120px;
  height: 35px;
  border-radius: 50px;
}
.tags {
  display: flex;
  flex-wrap: wrap;
  height: 400px;
  overflow-y: scroll;
  cursor: pointer;
}
.tags::-webkit-scrollbar {
  display: none;
}
.tags div {
  width: 80px;
  padding: 10px 10px;
  font-size: 12px;
  text-align: center;
  /* width: 30px; */
}
.tags div:hover {
  color: red;
}

.mv-wrapper {
  // margin-left: 60px;
  margin-top: 30px;
      .video_wrap {
    display: grid;
    justify-content: space-around;
    grid-template-columns: repeat(auto-fill,12.25rem);

    .item_wrap {
      width: 11.25rem;
      .item {
        margin-bottom: 20px;
        .cover {
          position: relative;
          height: 6.75rem;
          .el-image {
            width: 100%;
            height: 100%;
            border-radius: 13px;
             box-shadow: 0 2px 4px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .04);
          }
          .count {
            position: absolute;
            font-size: 8px;
            z-index: 5;
            top: 2%;
            right: 2%;
            color: #fff;
          }
          .el-icon-caret-right {
            font-size: 15px;
          }
          .time {
            position: absolute;
            font-size: 8px;
            z-index: 5;
            bottom: 2%;
            right: 2%;
            color: #fff;
          }
        }
        .title {
          font-size: 15px;
          font-weight: 600;
          line-height: 20px;
          overflow: hidden;
          white-space: nowrap;
          text-overflow: ellipsis;
        }
        .name {
          font-size: 10px;
          color: #6e6e69;
        }
      }
    }
  }

}
</style>